#!/usr/bin/env python
import sys, string, time
from boinc import *

INPUT_FILENAME = "in"
OUTPUT_FILENAME = "out"
  

def worker():
  print 'Upper-casing files'
  input_path = boinc_resolve_filename(INPUT_FILENAME)
  infile = boinc_fopen(input_path, 'r')

  output_path = boinc_resolve_filename(OUTPUT_FILENAME)
  outfile = boinc_fopen(output_path, 'w')

  char = infile.read(1)
  while char != '':
    outfile.write(string.upper(char))
    char = infile.read(1)

  outfile.close()
  infile.close()
	
def trickleUpCredit():
  counter = 1000 # 100 minutes of fake work
  while counter != 0:
    time.sleep(6)
    boinc_send_trickle_up('partial_credit', "0.1")
    counter = counter - 1

retval = boinc_init()

if (retval):
	sys.exit(retval)

worker()
trickleUpCredit()
#add here code to checkpoint
boinc_finish()
